package com.nexus.service.sys.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nexus.core.exception.ServiceException;
import com.nexus.core.service.BaseService;
import com.nexus.core.sys.entity.SysLog;
import com.nexus.core.sys.dto.SysLogDTO;
import com.nexus.service.sys.mapper.SysLogMapper;
import com.nexus.service.sys.service.mapstruct.SysLogWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 系统日志Service
 *
 * @author 路正宁
 * @version 2023-03-15
 */
//@DS("zxhy_platform_db")
//@Service
@Transactional(rollbackFor = {ServiceException.class,Exception.class, RuntimeException.class})
public class SysLogService extends BaseService<SysLogMapper, SysLog,SysLogDTO,SysLogWrapper> {

    @Autowired
    private SysLogWrapper sysLogWrapperImpl;
    /**
     * 根据id查询
     * @param id
     * @return
     */
    public SysLogDTO findById(String id) {
        return baseMapper.findById ( id );
    }

    /**
     * 自定义分页检索
     * @param page
     * @param queryWrapper
     * @return
     */
    public IPage<SysLogDTO> findPage(Page<SysLogDTO> page, QueryWrapper queryWrapper) {
        queryWrapper.eq ("a.deleted", 0 ); // 排除已经删除
        return  baseMapper.findList (page, queryWrapper);
    }

    /**
     * 保存系统日志
     * @Date 2023/6/30 11:44
     * @Author luzhengning
     **/
    public SysLogDTO saveOrUpdate(SysLogDTO logDTO){
        try{
            SysLog entity = sysLogWrapperImpl.toEntity(logDTO);
            if(this.saveOrUpdate(entity)){
                return sysLogWrapperImpl.toDTO(entity);
            }
            return null;
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return null;
    }
}
